
clear all
set more off
cap log close
program drop _all
set matsize 11000, permanently

use "INTERMEDIATE/product_RMS_def10_firm_sampleE_06_15.dta", clear

*   New Variables
**************************
* Outcome variables
gen logprice = log(price)
gen logquantity = log(quantity)
gen logrevenue  = log(revenue)
gen logquantity_store     = log(quantity/num_store)
gen logquantity_storeweek = log(quantity/num)
gen logrevenue_store      = log(revenue/num_store)
gen logrevenue_storeweek  = log(revenue/num)
gen logstore=log(num_store)

* Fixed-effects
egen fe=group(module quarter)
qui tab cohort, gen(cohort_d)
qui tab quarter, gen(quarter_d)

*   Working file
save "INTERMEDIATE/temp.dta", replace

**
* TABLE
**

use "INTERMEDIATE/temp.dta", clear

keep if cohort>=3 & cohort<=23  
drop if age>16 
drop if age==0
drop if maxAge<=16
keep if flag_longitudinal=="Complete"

foreach num of numlist 5/23 {   
gen cohort_nd`num'=cohort_d`num'-((`num'-1)*cohort_d4-(`num'-2)*cohort_d3)
}

egen fe_new=group(firm module quarter)

areg logrevenue cohort_nd*, absorb(fe) cluster(module)
outreg2 using "OUTPUT/Table4.tex", replace tex keep(i.age) addtext(Cohort FE, Yes, Sector\&Time FE, Yes, Firm\&Sector\&Time FE, No, Sample, Balanced, Products, `SSS'`DDD')
areg logrevenue i.age cohort_nd*, absorb(fe) cluster(module)
outreg2 using "OUTPUT/Table4.tex", append tex keep(i.age) addtext(Cohort FE, Yes, Sector\&Time FE, Yes, Firm\&Sector\&Time FE, No, Sample, Balanced, Products, `SSS'`DDD')
areg logrevenue i.age cohort_nd*, absorb(fe_new) cluster(module)
outreg2 using "OUTPUT/Table4.tex", append tex keep(i.age) addtext(Cohort FE, Yes, Sector\&Time FE, No, Firm\&Sector\&Time FE, Yes, Sample, Balanced, Products, `SSS'`DDD')
areg logprice i.age cohort_nd*, absorb(fe) cluster(module)
outreg2 using "OUTPUT/Table4.tex", append tex keep(i.age) addtext(Cohort FE, Yes, Sector\&Time FE, Yes, Firm\&Sector\&Time FE, No, Sample, Balanced, Products, `SSS'`DDD')
areg logquantity i.age cohort_nd*, absorb(fe) cluster(module)
outreg2 using "OUTPUT/Table4.tex", append tex keep(i.age) addtext(Cohort FE, Yes, Sector\&Time FE, Yes, Firm\&Sector\&Time FE, No, Sample, Balanced, Products, `SSS'`DDD')

erase "INTERMEDIATE/temp.dta"

